// import Cookies from "js-cookie";
import wsCache from "./storage";

const TokenKey = "authorized-token";
const RefreshTokenKey = "x-authorized-token"
const TenantId = 'tenant-id'

const isTokenExpKey = 'authorized-token-isTokenExp'

export function getTenantId() {
  return wsCache.get(TenantId)
}

export function setTenantId(tenantId: any) {
  wsCache.set(TenantId, tenantId)
}

export function setAccessToken(token: string) {
  // 19分钟 后端判断是20分钟
  wsCache.set(isTokenExpKey, true, { exp: 60 * 19 })
  wsCache.set(TokenKey, token, { exp: 60 * 60 * 24 })
}

export function getAccessToken() {
  return wsCache.get(TokenKey) as string;
}

export function clearAccessToken() {
  wsCache.delete(TokenKey)
  wsCache.delete(RefreshTokenKey)
  wsCache.delete(TenantId)
}

export function isTokenExp() {
  return !wsCache.get(isTokenExpKey)
}


export function setRefreshToken(refreshToken: string) {
  // 二十天 后端判断是三十天
  wsCache.set(RefreshTokenKey, refreshToken, { exp: 60 * 60 * 24 * 20 })
}
export function getRefreshToken() {
  return wsCache.get(RefreshTokenKey)
}